package servlets;
import dataManagers.*;
import entity.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class registerationServlet extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");

        String name = request.getParameter("name"); 
        String dob = request.getParameter("dob");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String accessToken=request.getParameter("accessToken");
        String uid=request.getParameter("uid");
        try{
        UserDM.createUser(new Users(username,password,name,dob,0,accessToken,uid));
        
        HttpSession session = request.getSession(true);
        RequestDispatcher dispatcher;
        
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        response.getWriter().write("<message>Registeration Successful!</message>"); 
        }catch(Exception e){
        	response.setContentType("text/xml");
            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().write("<message>Registeration Unsuccessful!</message>"); 
            
        }
        /*   String errorMsg="";
        request.setAttribute("errorMsg", errorMsg);
        dispatcher = request.getRequestDispatcher("index.jsp");
        dispatcher.forward(request, response);
    */

  }
}